package top.milkbox.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import top.milkbox.domain.Order;
import top.milkbox.service.OrderService;
import top.milkbox.mapper.OrderMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xiaoguo
 * @description 针对表【tb_order】的数据库操作Service实现
 * @createDate 2022-04-21 17:47:56
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
        implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * SELECT * FROM tb_order
     * WHERE company="tt" AND order_number="1003"
     * ORDER BY datatime desc;
     *
     * @param company     公司名称
     * @param orderNumber 订单号
     * @return 订单列表
     */
    @Override
    public List<Order> findByCompanyAndOrderNumberOrder(String company, String orderNumber) {
        // 判断orderNumber是否为空字符串
        if ("".equals(orderNumber) || " ".equals(orderNumber)) {
            orderNumber = null;
        }

        Map<String, Object> map = new HashMap<>();
        map.put("company", company);
        map.put("order_number", orderNumber);

        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        // 为 true 则在 map 的 value 为 null 时调用 isNull 方法,为 false 时则忽略 value 为 null 的
        wrapper.allEq(map, false);
        wrapper.orderByDesc("datatime");

        return orderMapper.selectList(wrapper);
    }
}




